﻿@using EC.Entity.Enum;
@{
    Layout = "~/Views/Shared/_Dialog.cshtml";
}
@model EC.Entity.Response.BankCard.BankCardResponse

<section class="container-fluid" style="background-color: white;">
    <form class="form-horizontal m15_t" id="form">
        <div class="tab-content">
            <input type="hidden" id="Id" name="Id" value="@(Model.Id)">
            <div class="tab-pane fade in active" id="home">
                <div class="form-group">
                    <label class="wd100 control-label">类型：</label>
                    <div class="wd350">
                        <select name="cardType" class="form-control">
                            <option value="">请选择</option>
                            @{
                                foreach (var dict in (IDictionary<int, string>)ViewBag.CardType)
                                {
                                    if (dict.Key == Model.CardType)
                                    {
                                        <option value="@dict.Key" selected>@dict.Value</option>
                                    }
                                    else
                                    {
                                        <option value="@dict.Key" )>@dict.Value</option>
                                    }
                                }
                            }
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="wd100 control-label">商户：</label>
                    <div class="wd350">
                        <select name="merchantId" class="form-control" @(Model.CardType == (int)CardType.备用卡 ? "disabled" : "")>
                            <option value="0">未分配</option>
                            @{
                                if (Model != null && Model.MerchantResponse != null && Model.MerchantResponse.Any())
                                {
                                    foreach (var item in (List<EC.Entity.Response.Merchant.MerchantResponse>)Model.MerchantResponse)
                                    {
                                        if (Model.MerchantId == item.Id)
                                        {
                                            <option value="@(item.Id)" selected>@(item.Name)</option>
                                        }
                                        else
                                        {
                                            <option value="@(item.Id)">@(item.Name)</option>
                                        }
                                    }
                                }
                            }
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="wd100 control-label">状态：</label>
                    <div class="wd350">
                        <select name="status" class="form-control">
                            <option value="">请选择</option>
                            @{
                                foreach (var dict in (IDictionary<int, string>)ViewBag.BankCardStatus)
                                {
                                    if (dict.Key == 2)
                                    {
                                        continue;
                                    }
                                    if (dict.Key == Model.Status)
                                    {
                                        <option value="@dict.Key" selected>@dict.Value</option>
                                    }
                                    else
                                    {
                                        <option value="@dict.Key" )>@dict.Value</option>
                                    }
                                }
                            }
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="wd100 control-label">冻结：</label>
                    <div class="wd350">
                        <select name="frozen" class="form-control">
                            <option value="">请选择</option>
                            @{
                                foreach (var dict in (IDictionary<int, string>)ViewBag.BankCardFrozen)
                                {
                                    if (dict.Key == Model.Frozen)
                                    {
                                        <option value="@dict.Key" selected>@dict.Value</option>
                                    }
                                    else
                                    {
                                        <option value="@dict.Key" )>@dict.Value</option>
                                    }
                                }
                            }
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="wd100 control-label">上限：</label>
                    <div class="wd350">
                        <input class="form-control" type="text" name="UpperLimit" maxlength="6" value="@(Model.UpperLimit)" autocomplete="off">
                    </div>
                </div>
            </div>
        </div>
    </form>
</section>
@section footerScript{
    <script type="text/javascript">
        $(function () {
            $("select[name='cardType']").change(function () {

                var cardtype = $(this).find("option:selected").val()
                if (cardtype == 0) {
                    $("select[name='merchantId']").find("option[value='0']").prop("selected", true);
                    $("select[name='merchantId']").attr("disabled", true);
                } else {
                    $("select[name='merchantId']").removeAttr("disabled")
                }
                
            });
        });
        function save() {

            var cover = FlashPay.UI.Mask({
                obj: $("body"),
                opacity: 0.5
            });

            var data = $("#form").serializeJSON();
            //状态
            //data.status = $("input[name='status'][checked]").val();

            FlashPay.Util.Ajax({
                type: "POST",
                url: "/BankCard/SaveBankCard",
                data: data,
                success: function (res) {
                    if (res.success) {
                        cover.Remove();
                        FlashPay.UI.DialogOpener().Tip_success("操作成功！");
                        FlashPay.UI.DialogOpener().doSearch();
                        FlashPay.UI.CloseDialog();
                    } else {
                        cover.Remove();
                        FlashPay.UI.Tip_short_warning("操作失败！" + res.message);
                    }
                },
                error: function (json) {
                    cover.Remove();
                    FlashPay.UI.Tip_warning("操作失败！请查看网络，请重试。");
                }
            });

        }
    </script>
}